package com.zlx.mapper;

import com.zlx.entities.Student;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;

import java.util.List;

/**
 * @Author 周罗校
 * @Description
 * @ClassName StudentMapperInterface
 * @date 2020.10.10 15:10:41
 * 该版权归周罗校所有，最终解释权以官方为准
 */
public interface StudentMapperInterface {
    //批量添加
    @InsertProvider(type = StudentMapperProvider.class,method="addBitch")
    int addbitchStudent(List<Student> list);
    //批量删除
    @DeleteProvider(type = StudentMapperProvider.class,method="deleteBitch")
    int deletebitchStudentById(Integer[] ids);
    //修改学生
    @UpdateProvider(type = StudentMapperProvider.class,method="update")
    int updateStudent(Student student);

    List<Student> findAllStudent(@Param("name")String name, @Param("start") Integer start, @Param("end") Integer end);

    //关联查询，一对一
    @Select("select * from student")
    @Results(value = {
            @Result(one = @One(select = "com.zlx.mapper.AddressMapperInterface.getAddrById",fetchType = FetchType.LAZY),property = "address",column = "addr_id"),
    })
    List<Student> getStudentList();

    //关联查询多对一
    @Select("select * from student")
    @Results(value = {
            @Result(many = @Many(select = "com.zlx.mapper.CourseMapperInterface.getCourseById"),property = "list",column = "stu_id")
    })
    List<Student> getStudentListMany();

    //一对多和一对一结合查询
    @Select("select * from student")
    @Results(value = {
            @Result(one = @One(select = "com.zlx.mapper.AddressMapperInterface.getAddrById",fetchType = FetchType.LAZY),property = "address",column = "addr_id"),
            @Result(many = @Many(select = "com.zlx.mapper.CourseMapperInterface.getCourseById",fetchType = FetchType.LAZY),property = "list",column = "stu_id")
    })
    List<Student> getList();
}
